package com.java01.misc.eventdriven;

import java.util.ArrayList;
import java.util.List;

/**
 * 3 Custom event firer 
 * A simple event firer that add/remove custome event listeners and fire the event to all listeners.
 */
public class CustomEventFirer {

	private List<CustomEventListener> listeners = new ArrayList<CustomEventListener>();
	
	public void addCustomEventListener(CustomEventListener listener){
		if(!listeners.contains(listener)){
			listeners.add(listener);
		}
	}
	
	public void removeCustomEventListener(CustomEventListener listener){
		if(listeners.contains(listener)){
			listeners.remove(listener);
		}
	}
	
	public void fireCustomEvent(CustomEvent event){
		for(CustomEventListener listener:listeners){
			listener.customEventOccurs(event);
		}
	}
}
